package com.zyh.system.service.impl;

import com.zyh.system.dao.impl.MovieDaoImpl;
import com.zyh.system.domain.Movie;
import com.zyh.system.service.MovieService;

import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * @Author zyh
 * @Date 2024/8/1 18:54
 * @Description
 */

public class MovieServiceImpl implements MovieService {
    public static final Scanner INPUT = new Scanner(System.in);
    public static final MovieDaoImpl MOVIE_DAO = new MovieDaoImpl();

    /**
     * 添加电影功能
     *
     * @param
     * @param
     */
    @Override
    public void add(Map<Movie, Integer> map) {
        System.out.println("请输入添加的电影名称：");
        String movieName = INPUT.next();
        System.out.println("请输入添加的电影类型：");
        String movieType = INPUT.next();
        System.out.println("请输入添加的电影人气：");
        int moviePopularity = INPUT.nextInt();
        Movie movie = new Movie(movieName, movieType);
        boolean flag = MOVIE_DAO.add(map, movie, moviePopularity);
        if (flag) {
            System.out.println("添加成功！");
        } else {
            System.out.println("添加失败！");
        }
    }

    /**
     * 展示所有电影信息
     *
     * @param map
     */
    @Override
    public void showMovieInfo(Map<Movie, Integer> map) {
        MOVIE_DAO.showMovieInfo(map);
    }

    /**
     * 展示最高人气电影
     *
     * @param map
     */
    @Override
    public void showMax(Map<Movie, Integer> map) {
        Map<Movie, Integer> showMax = MOVIE_DAO.showMax(map);
        Set<Movie> keySet = showMax.keySet();
        for (Movie key : keySet) {
            Integer value = map.get(key);
            System.out.println("电影名称：" + key.getMovieName() + "\n" + "电影类型：" + key.getMovieType() + "\n" + "电影人气：" + value);
            System.out.println();
        }
    }
}
